package com.sduept.nwld.dataserver.rest;

import com.sduept.permission.manager.PersonnelManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@Slf4j
@WebServlet(name = "testFile", urlPatterns = "/rest/file")
public class TestServlet extends HttpServlet {

	private static final long serialVersionUID = -1126842510486313510L;
	@Autowired
	PersonnelManager orgManager;
	protected void processRequest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.getWriter().write("培不拉稀玉维奇！！！！！");
		response.getWriter().flush();
		/*if(request.getSession().getAttribute("loginUser")==null){
			return;
		}
		response.setContentType("application/octet-stream");
        response.setHeader("Content-disposition", "attachment; filename=test.zip" 
                + "");

        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        try {
            // bis = new BufferedInputStream(new
            // FileInputStream(getServletContext().getRealPath("" + filename)));
            bis = new BufferedInputStream(new FileInputStream("C:\\Users\\wk\\Desktop\\test.zip"));
            bos = new BufferedOutputStream(response.getOutputStream());

            byte[] buff = new byte[2048];
            int bytesRead;

            while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
                bos.write(buff, 0, bytesRead);
            }
            log.info("OK=========================");
        } catch (final IOException e) {
            log.info("出现IOException." + e);
        } finally {
            if (bis != null)
                bis.close();
            if (bos != null)
                bos.close();
        }*/
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		processRequest(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		 processRequest(request, response);
		
	}

}
